#include"Teacher.h"
#include<string.h>
#include <stdio.h>
void InitTeacher(Teach *t, const char *name, int age)
{
    t->age=age;
    t->size=0;
    strcpy(t->Name,name);
}

void InserStu(Teach *t, int id, const char *StuName)
{
    if(t->size==StuSize)
    {
        printf("数组已满，不允许在插入学生数据\n");
        return;
    }
    InitStu(&t->s[t->size++],id,StuName);

}
void RemovebyIndex(Teach *t,int index)
{
    for(int i=index;i<t->size-1;i++)
    {
        t->s[i]=t->s[i+1];
    }
    t->size--;
}

void RmStuByID(Teach *t, int ID)
{
   for(int i=0;i<t->size;i++)
   {
    if(t->s[i].id==ID)
    {
        RemovebyIndex(t,i);
        i--;//后面覆盖后导致原来这个位置不被检测，所以需要重新检测
    }
   } 
}
void RmStuByname(Teach *t,const char *name)
{
    for(int i=0;i<t->size;i++)
    {
        if(strcmp(t->s[i].Name,name)==0)
        {
            RemovebyIndex(t,i);
            i--;
        }
    }
}
Stu* FindStuByName(Teach *t,const char *name)
{
    for(int i=0;i<t->size;i++)
    {
        if(strcmp(t->s[i].Name,name)==0)
        {
           return &t->s[i];
        }
    }
    return NULL;
}

void PrintTeacher(Teach *t)
{
    printf("老师姓名：%s 年龄：%d\n",t->Name,t->age);
    printf("学生信息：\n");
    for(int i=0;i<t->size;i++)
    {
        PrintStu(&t->s[i]);
    }
}
